package com.zyzy.leftfourdead.adapter.autumnfestivaladapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.zyzy.leftfourdead.R;
import com.zyzy.leftfourdead.bean.AutumnBean;

import java.util.List;

/**
 * Created by Administrator on 2016/8/21.
 * 这是 水产五折 顶部广告栏的适配器
 */
public class AutumnFragmentTopAdapter extends PagerAdapter {
    private Context context = null;
    private List<AutumnBean.BannerBean> list = null;
    private LayoutInflater inflater = null;
    private SimpleDraweeView imageView_water_listView__top_item;

    public AutumnFragmentTopAdapter(Context context, List<AutumnBean.BannerBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = inflater.inflate(R.layout.item_fragment_water_listview_top, container, false);

        imageView_water_listView__top_item = (SimpleDraweeView) view.findViewById(R.id.imageView_water_listView__top_item);

        final String imageUrl = list.get(position).getPath();
        if (imageUrl != null) {
            Glide.with(context).load(imageUrl).into(imageView_water_listView__top_item);
//            viewHolder.imageView_water_listView_item.setImageURI(Uri.parse(imageUrl));
        }

        container.addView(view);
        return view;
    }

/*    public WaterBean.BannerBean parseJsonToBannerBean(String jsonString) {
        Gson gson = new Gson();
        WaterBean.BannerBean bean = gson.fromJson(jsonString, new TypeToken<WaterBean.BannerBean>() {
        }.getType());
        return bean;
    }*/
    public void reloadListView(List<AutumnBean.BannerBean> data,boolean isClear){
        if (isClear){
            list.clear();
        }
        list.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
